//
//  NewsFirstRecImageCell.m
//  JJHW_coreData
//
//  Created by lizhenqiang on 16/4/10.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "NewsFirstRecImageCell.h"
#import "ZiXunDetailViewController.h"
@interface NewsFirstRecImageCell()<JCTopicDelegate>

@end

@implementation NewsFirstRecImageCell

- (void)awakeFromNib {
    // Initialization code
    
    self.frame = CGRectMake(0, 0, DeviceWidth, kScaleFrom_iphone6_Desgin(230));//200
    _myWidth = DeviceWidth;
    _myHeight = self.frame.size.height;
    _pageControl.frame = CGRectMake(10, _myHeight-40, _myWidth-20, 37);
    _pageControl.currentPageIndicatorTintColor = TabBarBjSelectColor;
    _pageControl.pageIndicatorTintColor = [UIColor whiteColor];
    //实例化
    _Topic.frame = CGRectMake(0, 0, _myWidth, _myHeight);
    _zzcImageView.frame = CGRectMake(0, 0, _myWidth, _myHeight);
    [_Topic setSelf];
    _Topic.scrollSecond = 5.0f;
    //代理
    _Topic.JCdelegate = self;
    //更新
    _Topic.style = scrollStyleAuto;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    // Configure the view for the selected state
}
- (CGSize)sizeThatFits:(CGSize)size {
    CGFloat totalHeight = 0;
    totalHeight += [self.Topic sizeThatFits:size].height;
    return CGSizeMake(size.width, totalHeight);
}

-(void)setCellData:(NSMutableArray *)array
{
    self.dataArray = array;
    if (array.count>0) {
        //加入数据
        _Topic.pics = array;
        //更新
        _Topic.style = scrollStyleNone;
        [_pageControl setNumberOfPages:array.count];
        [_Topic upDate];
        if (array.count>1) {
            _pageControl.hidden = NO;
        }
        else
        {
            _pageControl.hidden = YES;
        }
        
    }
    else
    {
        _pageControl.hidden = YES;
        [_pageControl setNumberOfPages:0];
        UIImageView *image =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _myWidth, _myHeight)];
        image.contentMode = UIViewContentModeScaleToFill;//UIViewContentModeScaleAspectFill  
        image.image = kplaceholderImage240;
        [_Topic addSubview:image];
    }
}
-(void)didClick:(id)data andView:(UIView *)view
{
    NewsRecoImageObj *obj = (NewsRecoImageObj *)data;
    ZiXunDetailViewController *detail = [[ZiXunDetailViewController alloc] init];
    detail.titleForNav = @"资讯详情";
    detail.shareImageStr = obj.recoImage;
    detail.newsId = obj.internalBaseClassIdentifier;
    [self.VC.navigationController pushViewController:detail animated:YES];
    
//    Person *_person = [Person sharePerson];
//    if (_person.scrollTimer) {
//        [_person.scrollTimer setFireDate:[NSDate distantFuture]];
//    }
//    NSMutableArray *photos = [[NSMutableArray alloc] init];
//    if ([self.dataArray count]>0)
//    {
//        for (int i = 0; i < [self.dataArray count]; i++) {
//            // 替换为中等尺寸图片
//            NewsRecoImageObj *obj = [_dataArray objectAtIndex:i];
//            
//            MJPhoto *photo = [[MJPhoto alloc] init];
//            //photo.image = [UIImage imageNamed:[ImageArray objectAtIndex:i]];
//            //            NSString * getImageStrUrl = [NSString stringWithFormat:@"%@%@",PIC_URL,obj.key];
//            
//            //            NSString *getImageStrUrl = [NSString stringWithFormat:@"%@%@?imageView2/1/w/640/h/370",PIC_URL,obj.key];
//            
//            NSString *getImageStrUrl = obj.recoImage;//
//            photo.url = [NSURL URLWithString:getImageStrUrl];
//            photo.srcImageView = nil;//(UIImageView *)view
//            [photos addObject:photo];
//        }
//        
//        // 2.显示相册
//        MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
////        browser.delegate =self;
//        browser.currentPhotoIndex = view.tag-1; // 弹出相册时显示的第一张图片是？里外乱了
//        browser.photos = photos; // 设置所有的图片
//        [browser show];
//    }
//    else
//    {
//        //        [self.VC.view makeToast:@"无图片" duration:1 position:@"center"];
//    }
}
-(void)currentPage:(int)page total:(NSUInteger)total{
    //    _label1.text = [NSString stringWithFormat:@"Current Page %d",page+1];
        _pageControl.numberOfPages = total;
        _pageControl.currentPage = page;
//    self.pageLabel.text = [NSString stringWithFormat:@"%d/%d",page+1,(int)total];
}

@end
